package com.zhang.webadmin.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 * 后台管理用户表
 *
 * @TableName acl_user
 */
@TableName(value = "acl_user")
@Data
public class AclUser implements Serializable, UserDetails {
    /**
     * id
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 登录名称
     */
    @NotBlank(message = "登录名称不能为空")
    private String loginName;

    /**
     * 登录密码
     */
    @JsonIgnore
    @NotBlank(message = "登录密码不能为空")
    private String loginPassword;

    /**
     * 显示名称
     */
    @NotBlank(message = "显示名称不能为空")
    private String showName;

    /**
     * 状态 1：正常 0：冻结
     */
    private Integer status;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    @TableField(exist = false)
    private List<GrantedAuthority> authorities;

    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @JsonIgnore
    @Override
    public String getPassword() {
        return this.loginPassword;
    }

    @JsonIgnore
    @Override
    public String getUsername() {
        return this.loginName;
    }
}